#pragma once
#include "ControlBase.h"

class ProgressBar : public Control
{
public:
	virtual UIClass Type() { return UIClass::UI_ProgressBar; }
	bool IsContainer() override
	{
		return false;
	}
	float Boder = 1.5f;
	float PercentageValue = 0.5f;
	ProgressBar(int x, int y, int width = 120, int height = 24)
	{
		this->Location = POINT{x, y};
		this->Size = SIZE{width, height};
		this->BackColor = Colors::LightYellow4;
		this->ForeColor = Colors::LawnGreen;
	}
	void Update() override
	{
		if (this->IsVisual == false)
			return;
		auto d2d = this->Render;
		bool isUnderMouse = this->MostParent->UnderMouse == this;
		bool isSelected = this->MostParent->Selected == this;
		auto abslocation = this->AbsLocation;
		auto size = this->ActualSize();
		auto absRect = this->AbsRect;
		d2d->PushDrawRect(absRect.left, absRect.top, absRect.right - absRect.left, absRect.bottom - absRect.top);
		{
			Control *tmpc = this;
			List<Control *> need_render_background;
			while (tmpc->BackColor.a < 1.0f)
			{
				tmpc = tmpc->Parent;
				need_render_background.Add(tmpc);
			}
			if (this->BackColor.a < 1.0f)
			{
				for (int i = need_render_background.Count - 1; i >= 0; i--)
				{
					d2d->FillRect(abslocation.x, abslocation.y, size.cx, size.cy, need_render_background[i]->BackColor);
					if (need_render_background[i]->Image)
					{
						need_render_background[i]->RenderImage();
					}
				}
			}
			d2d->FillRect(abslocation.x, abslocation.y, size.cx, size.cy, this->BackColor);
			if (this->Image)
			{
				this->RenderImage();
			}
			d2d->FillRect(abslocation.x, abslocation.y, size.cx * this->PercentageValue, size.cy, this->ForeColor);
			// d2d->DrawRect(abslocation.x, abslocation.y, size.cx, size.cy, this->BolderColor, this->Boder);
		}
		d2d->PopDrawRect();
	}
};